package tests;

import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 */
public class TemplateSquarePage extends Utils {
    public static String url = "http://49.235.61.184:8080/template";

    public TemplateSquarePage() {
        super(url);
    }
    /**
     * 检查页面元素
     */
    public void checkTemplateSquarePageRight() throws IOException {
        //检查标题
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-heading > div > span"));
        //检查搜索框
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > span > span > input"));
        //检查“搜模板”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > span > span > span > button"));
        //检查“添加模板”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button"));
        //检查公共库
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-footer > div > div.ant-tabs-nav > div.ant-tabs-nav-wrap > div > div.ant-tabs-tab.ant-tabs-tab-active"));
        //检查私有库
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-footer > div > div.ant-tabs-nav > div.ant-tabs-nav-wrap > div > div:nth-child(2)"));
        //检查分类
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-card > div > form > div:nth-child(1) > div.label___12r3x > span"));
        //检查标签
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-card > div > form > div:nth-child(2) > div.label___12r3x > span"));
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
    /**
     * 测试一：添加模板
     */
    public void addTemplate() throws IOException, InterruptedException {
        //点击“添加模板”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击“保存”按钮
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button:nth-child(5)")).click();
        //添加模板名称
        driver.findElement(By.cssSelector("#name")).sendKeys("测试模板");
        //添加分类
        driver.findElement(By.cssSelector("#category")).sendKeys("测试");
        //勾选添加到公共库
        driver.findElement(By.cssSelector("#survey-modal-container > div > div.ant-modal-wrap > div > div.ant-modal-content > div.ant-modal-body > form > div:nth-child(4) > div > div > div > div > label > span.ant-checkbox > input")).click();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击“保存”按钮
        driver.findElement(By.cssSelector("#survey-modal-container > div > div.ant-modal-wrap > div > div.ant-modal-content > div.ant-modal-footer > button.ant-btn.ant-btn-primary")).click();
        Thread.sleep(3000);
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击“关闭”按钮
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm.ant-btn-dangerous")).click();
        Thread.sleep(1000);
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //检查是否添加成功
        String str = driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.cardList > div > div > div > div > div:nth-child(1) > div > div > div > div.ant-card-body > div.ant-card-meta > div > div.ant-card-meta-title > a")).getText();
        assert str.equals("测试模板");
    }

    /**
     * 测试二：搜索模板
     */
    public void searchTemplate() throws IOException {
        //在搜索框中输入你想要查找的内容
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > span > span > input")).sendKeys("测试模板");
        //点击“搜模板”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-has-footer.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > span > span > span > button")).click();
        //如果显示“暂无数据”则“搜模板”按钮异常
        String str = driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.cardList > div > div > div > div > div > div.ant-empty-description")).getText();
        //屏幕截图
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        assert str.equals("暂无数据");
    }



}
